package org.walkerljl.boss.service.monitor.impl;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.walkerljl.boss.dao.identity.AppDao;
import org.walkerljl.boss.dao.monitor.MonitorObjectDao;
import org.walkerljl.boss.domain.identity.App;
import org.walkerljl.boss.domain.monitor.MonitorObject;
import org.walkerljl.boss.service.monitor.MonitorObjectService;
import org.walkerljl.boss.support.dao.BaseDao;
import org.walkerljl.boss.support.service.impl.JqueryDatatableBaseServiceImpl;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * MonitorObjectServiceImpl
 *
 * @author lijunlin
 */
@Service("monitorObjectService")
public class MonitorObjectServiceImpl extends JqueryDatatableBaseServiceImpl<Long, MonitorObject> implements MonitorObjectService {

    @Resource
    private MonitorObjectDao monitorObjectDao;
    @Resource
    private AppDao appDao;

    @Override
    public BaseDao<Long, MonitorObject> getDao() {
        return monitorObjectDao;
    }

    @Override
    public Map<String, Object> selectJqueryDatatablePage(MonitorObject condition) {
        Map<String, Object> resultMap = super.selectJqueryDatatablePage(condition);
        List<MonitorObject> monitorObjects = (List<MonitorObject>) resultMap.get(DATATABLE_DATA_KEY);
        if (CollectionUtils.isEmpty(monitorObjects)) {
            return resultMap;
        }
        for (MonitorObject monitorObject : monitorObjects) {
            App app = appDao.selectByKey(monitorObject.getAppId());
            if (app != null) {
                monitorObject.setAppName(app.getName());
            }
        }
        return resultMap;
    }
}
